import axios from 'axios'
import querystring from 'querystring'

export const getCategory = (category) => {
    return axios.get('/api/category/get/' + category);
}

/* export const getShopList = (kind, page, size, params) => {
    return axios.get('/api/home/get/shoplist/');
} */
// 查询商店列表
export const getShopList = (kind, page, size, params) => {
    let query = querystring.stringify(params)
    return axios.request({
        url: '/api/shop/get/shoplist/' + kind + '/' + page + '/' + size + '/?' + query,
        method: 'get'
    })
}

export const getShopDetail = (shopName) => {
    return axios.get('/api/shop/detail/'+shopName);
}

export const getShopComment = (shopId) => {
    return axios.get('/api/comment/get/'+shopId);
}

// 加入购物车
export const joinCart = (foodId, userId) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/food/join/cart',
    method: 'post',
    data:{
      foodId: foodId,
      userId: userId
    }
  })
}
// 获取购物车列表
export const getCart = (userId) => {
  return axios.get('/api/food/get/cart/'+userId);
}
//删除购物车商品
export const delCartFood = (userId, foodId) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/food/delCartFood',
    method: 'post',
    data: {
      foodId: foodId,
      userId: userId
    }
  })
}

//获取用户
export const getUser = (userId) => {
  return axios.get('/api/user/get/'+userId);
}

//检察用户名是否存在
export const checkEmail = (email) => {
  return axios.get('/api/user/checkEmail?email='+email);
}

//检察商家邮箱是否存在
export const checkEmailShop = (email) => {
  return axios.get('/api/shop/checkEmail?email='+email);
}

//发送验证码
export const sendEmail = (email) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/emailCode',
    method: 'post',
    data: email
  })
}

//商家注册
export const shopRegister = (shop) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/shop/register',
    method: 'post',
    data: shop
  })
}
// 商家填写详细信息
export const editShopDetail = (shop) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/shop/editShopDetail',
    method: 'post',
    data: shop
  })
}

//用户注册
export const register = (user) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/register',
    method: 'post',
    data: user
  })
}

//用户登录
export const login = (remember, username, password) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/login',
    method: 'post',
    data: {
      rememberMe: remember,
      username: username,
      password: password
    }
  })
}

//用户注销
export const logout = (id) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/logout',
    method: 'post',
    data: id
  })
}

//修改用户信息
export const updateUser = (user) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/update',
    method: 'post',
    data: user
  })
}


//修改密码
export const updatePwd = (userId, usernamem, form) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/updatePwd',
    method: 'post',
    data: {
      userId: userId,
      username: usernamem,
      editPass: form
    }
  })
}


//获取热门搜索商家
export const getHotSearch = () => {
  return axios.get("/api/shop/hotSearch");
}
//获取正在搜索的匹配商家
export const getSearching = (search) => {
  return axios.get("/api/shop/searching?search="+search);
}
//增加搜索次数
export const addSearchNum = (id) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/shop/addSearchNum',
    method: 'post',
    data: id
  })
}

//生成订单
export const generatebOrder = (user, foodList, total) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/generateOrder',
    method: 'post',
    data: {
      user: user,
      foodList: foodList,
      total: total
    }
  })
}

//修改订单信息
export const editOrderMain = (orderData) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/orderMainEdit',
    method: 'post',
    data: orderData
  })
}

//订单收货
export const receive = (orderId) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/receive',
    method: 'post',
    data: orderId
  })
}

//订单评价
export const comment = (comment) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/comment',
    method: 'post',
    data: comment
  })
}

//支付
export const orderPay = (alipay) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/pay/alipay',
    method: 'post',
    data: alipay
  })
}

//支付
export const payStatus = (orderList, userId) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/pay/success/'+userId,
    method: 'post',
    data: orderList
  })
}

//修改用户信息
export const editUser = (user) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/user/update',
    method: 'post',
    data: user
  })
}

//提交订单
export const subOrder = (orderData) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/subOrder',
    method: 'post',
    data: orderData
  })
}

//根据用户id获取订单列表
export const getOrder = (userId) => {
  return axios.get('/api/order/getByUser/'+userId);
}

// 检查是否填写地址和手机号
export const checkPay = (orderId, userId) => {
  return axios.request({
    headers: {
      'Content-Type': 'application/json'
    },
    url: '/api/order/checkPay',
    method: 'post',
    data: {
      orderId:orderId,
      userId:userId
    }
  })
}
